#ifndef CLIENTSOCKET_H
#define CLIENTSOCKET_H

#include <QJsonDocument>
#include <QJsonObject>
#include <QTcpSocket>
#include <QJsonArray>
#include "EnumType.h"

class ClientSocket : public QTcpSocket
{
    Q_OBJECT
public:

    explicit ClientSocket(QObject *parent = nullptr);

    void connectToServer();

    bool readConfFile(const QString &);

    bool isConnected() const {return is_connected;}

    void move(MoveDirection,int);

    void servosMove(Servos,int);

    void stop();

signals:

private slots:

    void recv();

private:

    using QTcpSocket::readyRead;

    QMap<MoveDirection,QString> dir_map = {
        {MoveDirection::Left,"turn_left"},
        {MoveDirection::Right,"turn_right"},
        {MoveDirection::Back,"Back_off"},
        {MoveDirection::Front,"advance"},
        {MoveDirection::FrontLeft,"left_advance"},
        {MoveDirection::FrontRight,"right_advance"},
        {MoveDirection::BackLeft,"left_back"},
        {MoveDirection::BackRight,"right_back"},
        {MoveDirection::Stop,"stop"}
    };

    QMap<Servos,QString> servos_map = {
        {Servos::Forearm,"Foream"},
        {Servos::BigArm,"Big_Arm"},
        {Servos::platform,"plateform"},
        {Servos::clip,"clip"}
    };

    QString server_ip = "127.0.0.1";

    unsigned short server_port = 8080;

    bool is_connected = false;
};

#endif // CLIENTSOCKET_H
